<template>
  <div class="m-search">
    <h1>Search</h1>  

    <div class="search f-cb">
       <input type="search" placeholder="search somthing" v-model="searchTxt" :val="searchTxt">
       <i v-show="!searchTxt" class="iconfont icon-search"></i>
    </div>
   
    <button class="search-btn" @click="handleSearch">Search</button>

    <div class="robot-box">
      <i class="iconfont icon-robot"></i>
    </div>

  </div>
</template>

<script>
export default {
  name: 'search',
  data () {
    return {
      searchTxt: localStorage.getItem('searchTxt') || ''
    }
  },
  methods:{
    handleSearch(){
      var searchTxt = this.searchTxt;
      this.storeDate('searchTxt', searchTxt);
      this.$router.push({name:'Result',params:{
        s: searchTxt
      }})
     
    },
    storeDate(key,val){
      localStorage.setItem(key, val)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.search{
  position: relative;
  margin-top: 10px;
}
.search input{
  width: 80%;
  height: 30px;
  margin: 0 auto;
}
.search i{
  box-sizing: border-box;
  padding: 0.02rem 0;
  position: absolute;
  right: .46rem;
  font-size: 0.20rem;
}
.search-btn{
  margin-top: 20px;
}
.robot-box {
  margin-top: 30px;
}
.robot-box i{
  font-size: 1.00rem;
}
</style>
